#include <iostream>
#include <cstring>
using namespace std;
int a[200001],c[200001],bark[200001];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin >> t;
    while(t--){
        long long ans = 0;
        memset(c,0,sizeof(c));
        memset(bark,0,sizeof(bark));
        int n;
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        int flag = 1;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                if(a[i] == a[j]){
                    for(int k = i + 1;  k < j; k++){
                        if(bark[k] != 0){
                            flag = bark[k] * -1;
                            bark[i] = flag;
                            bark[j] = bark[i];
                            break;
                        }
                    }
                    bark[i] = flag;
                    bark[j] = flag;
                }
            }
            bark[i] = flag;
            flag *= -1;
        }
        for(int i = 1; i < n; i++){
            for(int m = i - 1; m >= 0; m--){
                if(bark[m] == bark[i]){
                    if(a[m] != a[i]){
                        c[i] = 0;
                        break;
                    }else{
                        c[i] = a[i];
                        break;
                    }
                }
            }
            ans += c[i];
        }
        cout << ans << endl;
    }
    return 0;
}
